package com.nthink.indicators.service.operationindex.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nthink.indicators.mapper.operationindex.WorkloadMapper;
import com.nthink.indicators.pojo.operationindex.workload.*;
import com.nthink.indicators.pojo.pie.PieDataModel;
import com.nthink.indicators.service.operationindex.WorkloadService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WorkloadServiceImpl extends ServiceImpl<WorkloadMapper, Workload> implements WorkloadService {

    @Override
    public Workload getData(Date startTime, Date endTime) {
        Workload workload = new Workload();
        workload.setOutpatients(baseMapper.getOutpatients(startTime, endTime));
        workload.setInpatients(baseMapper.getInpatients(startTime, endTime));
        workload.setEmergencyPatients(baseMapper.getEmergencyPatients(startTime, endTime));
        workload.setDeath(baseMapper.getDeath(startTime, endTime));
        workload.setOperationInInpatients(baseMapper.getOperationInInpatients(startTime, endTime));
        workload.setOperationInOutpatients(baseMapper.getOperationInOutpatients(startTime, endTime));
        workload.setDischargedPatients(baseMapper.getDischargedPatients(startTime, endTime));
        return workload;
    }

    @Override
    public WorkloadYear getYearData(Integer year) {
        WorkloadYear workloadYear = new WorkloadYear();
        workloadYear.setOutYearPatients(baseMapper.getOutYearPatients(year));
        workloadYear.setInYearPatients(baseMapper.getInYearPatients(year));
        workloadYear.setDischargeYearPatients(baseMapper.getDischargeYearPatients(year));
        return workloadYear;
    }

    @Override
    public WorkloadBedYear getYearBedData(Integer year) {
        WorkloadBedYear workloadBedYear = new WorkloadBedYear();
        workloadBedYear.setTotalBedDays(baseMapper.getTotalBedDays(year));
        workloadBedYear.setAverageHospitalDays(baseMapper.getAverageHospitalDays(year));
        workloadBedYear.setTotalUseBedDays(baseMapper.getTotalUseBedDays(year));
        workloadBedYear.setBedUseCount(baseMapper.getBedUseCount(year));
        workloadBedYear.setBedUseRate(baseMapper.getBedUseRate(year));
        workloadBedYear.setDaysPerBed(baseMapper.getDaysPerBed(year));
        workloadBedYear.setTotalOpenBedDays(baseMapper.getTotalOpenBedDays(year));
        return workloadBedYear;
    }

    @Override
    public WorkloadDrug getDrugData(Date startTime, Date endTime) {
        WorkloadDrug workloadDrug = new WorkloadDrug();

        workloadDrug.setOutpatientPrescriptions(baseMapper.getOutpatientPrescriptions(startTime, endTime));
        workloadDrug.setAntibacterials(baseMapper.getAntibacterials(startTime, endTime));
        // workloadDrug.setAdverseDrugReactions(baseMapper.getAdverseDrugReactions(startTime, endTime));
        workloadDrug.setOutPatientEssentialDrugs(baseMapper.getOutPatientEssentialDrugs(startTime, endTime));
        workloadDrug.setEssentialDrugsPurchasedRate(baseMapper.getEssentialDrugsPurchasedRate(startTime, endTime));
        workloadDrug.setEssentialDrugsRateByInpatients(baseMapper.getEssentialDrugsRateByInpatients(startTime, endTime));

        return workloadDrug;
    }

    @Override
    public List<PieDataModel> getOperationInfo(Date startTime, Date endTime) {
        return baseMapper.getOperationInfo(startTime,endTime);
    }
}
